<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('电子签章') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('标题')" prop="actTitle">
        <el-input
          v-model="queryParams.applyTitle"
          size="small"
          :placeholder="$t('标题')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetFormTest('queryForm')">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="fundElectronicSealsList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" width="100">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="left" prop="tit" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-link type="primary" prop="applyTitle" @click="updateHandle(scope.row)">{{ scope.row.applyTitle }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('签约日期')" align="center" prop="signDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('备注')" align="center" prop="remake" width="380">
        <template slot-scope="scope">
          <span>{{ scope.row.remake }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('签约状态')" align="center" prop="sginState" width="180">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- 启动流程，终止流程，修改，删除 四个按钮  scope.row.documentId -->
          <ListBtn :bus-data="scope.row" has-permi="fund:contract" />
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="goToJava(scope.row)"
          >{{ $t('手动调用') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改合同信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="formOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm"
      append-to-body
    >
      <fundElectronicSealsForm ref="fundElectronicSealsForm" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listFundElectronicSeals,
  delFundElectronicSeals,
  goToJavaDate
} from '@/api/fund/contract/fundElectronicSeals'
import fundElectronicSealsForm from './fundElectronicSealsForm.vue'
export default {
  name: 'FundElectronicSealsList',
  components: {
    fundElectronicSealsForm
  },
  data() {
    return {
      title: this.$t('电子签章'),
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 事项申请表格数据
      electronicSealsList: [],
      fundElectronicSealsList: [],
      formOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applyTitle: undefined,
        fundId: this.$route.query.id
      },
      // 表单参数
      form: {
      },
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    resetFormTest(formName) {
      console.log(formName)
      this.queryParams.applyTitle = ''
      this.queryHandle()
    },

    /** 查询事项申请列表 */
    getList() {
      this.loading = true
      listFundElectronicSeals(this.queryParams).then(response => {
        console.log(response)
        this.fundElectronicSealsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    reset() {
      this.form = {
        id: undefined,
        applyTitle: undefined,
        fundId: undefined,
        createBy: undefined,
        updateBy: undefined,
        createTime: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.fundElectronicSealsForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.fundElectronicSealsForm.init(row)
      })
    },
    fetchTemplate(documentId) {
      const picUrl = process.env.VUE_APP_BASE_URL
      window.location.href = picUrl + '/contract/fundElectronicSeals/exportContract/' + documentId
      /* return request({
         url: '/contract/fundElectronicSeals/exportContract/' + documentId,
         method: 'post',
         responseType: 'blob'
       })*/
    },

    goToJava(row) {
      console.log(row)
      goToJavaDate(row.id).then(response => {
        console.log(response)
      })
    },

    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delFundElectronicSeals(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }
  }
}
</script>
